﻿using System;

using Unity.Connections;
using Unity.Credentials;

namespace Unity.Kafka
{
    public class UnityKafkaFactory : IUnityCommunicationFactory
    {
        public bool IsSupportedPull()
        {
            return true;
        }

        public bool IsSupportedPush()
        {
            return false;
        }

        public IUnityProducer NewProducer(IUnityCredentials credentials)
        {
            if(!credentials.GetType().IsSubclassOf(typeof(UnityKafkaCredentials)))
            {
                throw new Exception();
            }
            return new UnityKafkaProducer((UnityKafkaCredentials)credentials);
        }

        public IUnityConsumer NewPullConsumer(IUnityCredentials credentials)
        {
            if (!credentials.GetType().IsSubclassOf(typeof(UnityKafkaCredentials)))
            {
                throw new Exception();
            }
            return new UnityKafkaConsumer((UnityKafkaCredentials)credentials);
        }

        public IUnityConsumer NewPushConsumer(IUnityCredentials credentials, IUnityCallback callback)
        {
            throw new NotImplementedException();
        }
    }
}
